package com.tn.auth.config;

import com.tn.auth.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置文件
 *
 * @program: tn_aucy_java
 * @author: yangjiayao
 * @create: 2021/12/23
 */
@Configuration
public class TokenInterceptorConfig implements WebMvcConfigurer {
    /**
     * 拦截器实例
     */
    private TokenInterceptor tokenInterceptor;

    /**
     * 注入
     *
     * @param tokenInterceptor 拦截器实例
     */
    @Autowired
    public void setTokenInterceptor(TokenInterceptor tokenInterceptor) {
        this.tokenInterceptor = tokenInterceptor;
    }

    /**
     * 注册拦截器
     *
     * @param registry 注册器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器
        registry.addInterceptor(tokenInterceptor)
                .excludePathPatterns("/doc.html") // 登录路径不拦截
                .excludePathPatterns("/webjars/**") // 登录路径不拦截
                .excludePathPatterns("/aucy/login") // 登录路径不拦截
                .excludePathPatterns("/producer") // 生产系统路径不拦截
                .excludePathPatterns("/aucy/acceptTruckData") // 生产系统路径不拦截
                .excludePathPatterns("/aucy/acceptTruckPermitThroughData") // 生产系统路径不拦截
                .excludePathPatterns("/aucy/acceptTruckWeighingData") // 生产系统路径不拦截
                .addPathPatterns("/**"); // 所有路径都被拦截
    }
}
